package scuts.core;

import scuts.core.Flatten;
import utest.Assert;
using scuts.core.Flatten;

class FlattenTest 
{
  public function new() 
  {
    
  }
  /*
  public function testIterator()
  {
    var outer = [1...3, 1...3].iterator();
    var flat = outer.flatten();
    
    Assert.isTrue(flat.hasNext());
    Assert.same(1, flat.next());
    Assert.isTrue(flat.hasNext());
    Assert.same(2, flat.next());
    Assert.isTrue(flat.hasNext());
    Assert.same(1, flat.next());
    Assert.isTrue(flat.hasNext());
    Assert.same(2, flat.next());
    Assert.isFalse(flat.hasNext());
  }
  */
  public function testLazyIterator() 
  {
    var iter = function () return [1, 2].iterator();
    var outer = function () return [iter, iter].iterator();
    
    var flat = outer.flatten();
    
    
    var res = flat();
    
    Assert.isTrue(res.hasNext());
    Assert.same(1, res.next());
    Assert.isTrue(res.hasNext());
    Assert.same(2, res.next());
    Assert.isTrue(res.hasNext());
    Assert.same(1, res.next());
    Assert.isTrue(res.hasNext());
    Assert.same(2, res.next());
    Assert.isFalse(res.hasNext());
    
    // it was lazy, so a second one should work
    var res1 = flat();
    
    Assert.isTrue(res1.hasNext());
    Assert.same(1, res1.next());
    Assert.isTrue(res1.hasNext());
    Assert.same(2, res1.next());
    Assert.isTrue(res1.hasNext());
    Assert.same(1, res1.next());
    Assert.isTrue(res1.hasNext());
    Assert.same(2, res1.next());
    Assert.isFalse(res1.hasNext());
        
    
  }
  
}